home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / editing.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  55.1 KB  |  1,369 lines

  1. *editing.txt*   For Vim version 6.0.  Last change: 2001 Sep 19
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Editing files                        *edit-files*
  8.  
  9. 1.  Introduction        |edit-intro|
  10. 2.  Editing a file        |edit-a-file|
  11. 3.  Dialogs            |edit-dialogs|
  12. 4.  The current directory    |current-directory|
  13. 5.  The argument list        |argument-list|
  14. 6.  Writing            |writing|
  15. 7.  Writing and quitting    |write-quit|
  16. 8.  Editing binary files    |edit-binary|
  17. 9.  Encryption            |encryption|
  18. 10. Timestamps            |timestamps|
  19.  
  20. ==============================================================================
  21. 1. Introduction                        *edit-intro*
  22.  
  23. Editing a file with Vim means:
  24.  
  25. 1. reading the file into the internal buffer
  26. 2. changing the buffer with editor commands
  27. 3. writing the buffer into a file
  28.  
  29.                             *current-file*
  30. As long as you don't write the buffer, the original file remains unchanged.
  31. If you start editing a file (read a file into the buffer), the file name is
  32. remembered as the "current file name".
  33.  
  34.                             *alternate-file*
  35. If there already was a current file name, then that one becomes the alternate
  36. file name.  All file names are remembered in the file list.  When you enter a
  37. file name, for editing (e.g., with ":e filename") or writing (e.g., with (:w
  38. file name"), the file name is added to the list.  You can use this list to
  39. remember which files you edited and to quickly switch from one file to
  40. another with the CTRL-^ command (e.g., to copy text).  First type the number
  41. of the file and then hit CTRL-^.  {Vi: only one alternate file name}
  42.  
  43. CTRL-G        or                *CTRL-G* *:f* *:fi* *:file*
  44. :f[ile]            Prints the current file name (as typed), the
  45.             cursor position (unless the 'ruler' option is set),
  46.             and the file status (readonly, modified, read errors,
  47.             new file)).  See the 'shortmess' option about how tho
  48.             make this message shorter.  {Vi does not include
  49.             column number}
  50.  
  51. {count}CTRL-G        Like CTRL-G, but prints the current file name with
  52.             full path.  If the count is higher than 1 the current
  53.             buffer number is also given.  {not in Vi}
  54.  
  55.                             *g_CTRL-G*
  56. g CTRL-G        Prints the current position of the cursor in four
  57.             ways: Column, Line, Word and Byte.  If there are
  58.             characters in the line that take more than one
  59.             position on the screen (<Tab> or special character),
  60.             both the "real" column and the screen column are
  61.             shown, separated with a dash.  See also 'ruler'
  62.             option.  {not in Vi}
  63.  
  64.                             *v_g_CTRL-G*
  65. {Visual}g CTRL-G    Similar to "g CTRL-G", but Word, Line, and Byte counts
  66.             for the visually selected region are displayed.  In
  67.             Blockwise mode, Column count is also shown.  (For
  68.             {Visual} see |Visual-mode|.)
  69.             {not in VI}
  70.  
  71.                             *:file_f*
  72. :f[ile] {name}        Sets the current file name to {name}.
  73.  
  74. :buffers
  75. :files
  76. :ls            List all the currently known file names.  See
  77.             'windows.txt' |:files| |:buffers| |:ls|.  {not in
  78.             Vi}
  79.  
  80. Vim will remember the full path name of a file name that you enter.  In most
  81. cases when the file name is displayed only the name you typed is shown, but
  82. the full path name is being used if you used the ":cd" command |:cd|.
  83.  
  84.                             *home-replace*
  85. If the environment variable $HOME is set, and the file name starts with that
  86. string, it is often displayed with HOME replaced with "~".  This was done to
  87. keep file names short.  When reading or writing files the full name is still
  88. used, the "~" is only used when displaying file names.  When replacing the
  89. file name would result in just "~", "~/" is used instead (to avoid confusion
  90. with 'backupext' set to "~").
  91.  
  92. When writing the buffer, the default is to use the current file name.  Thus
  93. when you give the "ZZ" or ":wq" command, the original file will be
  94. overwritten.  If you do not want this, the buffer can be written into another
  95. file by giving a file name argument to the ":write" command.  For example: >
  96.  
  97.     vim testfile
  98.     [change the buffer with editor commands]
  99.     :w newfile
  100.     :q
  101.  
  102. This will create a file "newfile", that is a modified copy of "testfile".
  103. The file "testfile" will remain unchanged.  Anyway, if the 'backup' option is
  104. set, Vim renames or copies the original file before it will be overwritten.
  105. You can use this file if you discover that you need the original file.  See
  106. also the 'patchmode' option.  The name of the backup file is normally the same
  107. as the original file with 'backupext' appended.  The default "~" is a bit
  108. strange to avoid accidentally overwriting existing files.  If you prefer ".bak"
  109. change the 'backupext' option.  Extra dots are replaced with '_' on MS-DOS
  110. machines, when Vim has detected that an MS-DOS-like filesystem is being used
  111. (e.g., messydos or crossdos) or when the 'shortname' option is on.  The
  112. backup file can be placed in another directory by setting 'backupdir'.
  113.  
  114.                             *auto-shortname*
  115. Technical: On the Amiga you can use 30 characters for a file name.  But on an
  116.        MS-DOS-compatible filesystem only 8 plus 3 characters are
  117.        available.  Vim tries to detect the type of filesystem when it is
  118.        creating the .swp file.  If an MS-DOS-like filesystem is suspected,
  119.        a flag is set that has the same effect as setting the 'shortname'
  120.        option.  This flag will be reset as soon as you start editing a
  121.        new file.  The flag will be used when making the file name for the
  122.        ".swp" and ".~" files for the current file.  But when you are
  123.        editing a file in a normal filesystem and write to an MS-DOS-like
  124.        filesystem the flag will not have been set.  In that case the
  125.        creation of the ".~" file may fail and you will get an error
  126.        message.  Use the 'shortname' option in this case.
  127.  
  128. When you started editing without giving a file name, "No File" is displayed in
  129. messages.  If the ":write" command is used with a file name argument, the file
  130. name for the current file is set to that file name.  This only happens when
  131. the 'F' flag is included in 'cpoptions' (by default it is included).  This is
  132. useful when entering text in an empty buffer and then writing it to a file.
  133. If 'cpoptions' contains the 'f' flag (by default it is NOT included) the file
  134. name is set for the ":read file" command.  This is useful when starting Vim
  135. without an argument and then doing ":read file" to start editing a file.
  136.                             *not-edited*
  137. Because the file name was set without really starting to edit that file, you
  138. are protected from overwriting that file.  This is done by setting the
  139. "notedited" flag.  You can see if this flag is set with the CTRL-G or ":file"
  140. command.  It will include "[Not edited]" when the "notedited" flag is set.
  141. When writing the buffer to the current file name (with ":w!"), the "notedited"
  142. flag is reset.
  143.  
  144.                             *abandon*
  145. Vim remembers whether you have changed the buffer.  You are protected from
  146. losing the changes you made.  If you try to quit without writing, or want to
  147. start editing another file, Vim will refuse this.  In order to overrule this
  148. protection, add a '!' to the command.  The changes will then be lost.  For
  149. example: ":q" will not work if the buffer was changed, but ":q!" will.  To see
  150. whether the buffer was changed use the "CTRL-G" command.  The message includes
  151. the string "[Modified]" if the buffer has been changed.
  152.  
  153. If you want to automatically save the changes without asking, switch on the
  154. 'autowriteall' option.  'autowrite' is the associated Vi-compatible option
  155. that does not work for all commands.
  156.  
  157. If you want to keep the changed buffer without saving it, switch on the
  158. 'hidden' option.  See |hidden-buffer|.
  159.  
  160. ==============================================================================
  161. 2. Editing a file                    *edit-a-file*
  162.  
  163.                             *:e* *:edit*
  164. :e[dit] [++opt] [+cmd]    Edit the current file.  This is useful to re-edit the
  165.             current file, when it has been changed outside of Vim.
  166.             This fails when changes have been made to the current
  167.             buffer and 'autowriteall' isn't set or the file can't
  168.             be written.
  169.             Also see |++opt| and |+cmd|.
  170.             {Vi: no ++opt}
  171.  
  172.                             *:edit!*
  173. :e[dit]! [++opt] [+cmd]
  174.             Edit the current file always.  Discard any changes to
  175.             the current buffer.  This is useful if you want to
  176.             start all over again.
  177.             Also see |++opt| and |+cmd|.
  178.             {Vi: no ++opt}
  179.  
  180.                             *:edit_f*
  181. :e[dit] [++opt] [+cmd] {file}
  182.             Edit {file}.
  183.             This fails when changes have been made to the current
  184.             buffer, unless 'hidden' is set or 'autowriteall' is
  185.             set and the file can be written.
  186.             Also see |++opt| and |+cmd|.
  187.             {Vi: no ++opt}
  188.  
  189.                             *:edit!_f*
  190. :e[dit]! [++opt] [+cmd] {file}
  191.             Edit {file} always.  Discard any changes to the
  192.             current buffer.
  193.             Also see |++opt| and |+cmd|.
  194.             {Vi: no ++opt}
  195.  
  196. :e[dit] [++opt] [+cmd] #[count]
  197.             Edit the [count]th alternate file name (as shown by
  198.             :files).  This command does the same as
  199.             [count] CTRL-^.  But ":e #" doesn't work if the
  200.             alternate buffer doesn't have a file name, while
  201.             CTRL-^ still works then.
  202.             Also see |++opt| and |+cmd|.
  203.             {Vi: no ++opt}
  204.  
  205.                             *:ene* *:enew*
  206. :ene[w]            Edit a new, unnamed buffer.  This fails when changes
  207.             have been made to the current buffer, unless 'hidden'
  208.             is set or 'autowriteall' is set and the file can be
  209.             written.
  210.             If 'fileformats' is not empty, the first format given
  211.             will be used for the new buffer.  If 'fileformats' is
  212.             empty, the 'fileformat' of the current buffer is used.
  213.             {not in Vi}
  214.  
  215.                             *:ene!* *:enew!*
  216. :ene[w]!        Edit a new, unnamed buffer.  Discard any changes to
  217.             the current buffer.
  218.             Set 'fileformat' like |:enew|.
  219.             {not in Vi}
  220.  
  221.                             *:fin* *:find*
  222. :fin[d][!] [++opt] [+cmd] {file}
  223.             Find {file} in 'path' and then |:edit| it.
  224.             {not in Vi} {not available when the |+file_in_path|
  225.             feature was disabled at compile time}
  226.  
  227. :{count}fin[d][!] [++opt] [+cmd] {file}
  228.             Just like ":find", but use the {count} match in
  229.             'path'.  Thus ":2find file" will find the second
  230.             "file" found in 'path'.  When there are less matches
  231.             for the file in 'path' than asked for, you get an
  232.             error message.
  233.  
  234.                             *:ex*
  235. :ex [++opt] [+cmd] [file]
  236.             Same as |:edit|.
  237.  
  238.                             *:vi* *:visual*
  239. :vi[sual][!] [++opt] [+cmd] [file]
  240.             When entered in Ex mode: Leave |Ex-mode|, go back to
  241.             Normal mode.  Otherwise same as |:edit|.
  242.  
  243.                             *:vie* *:view*
  244. :vie[w] [++opt] [+cmd] file
  245.             When entered in Ex mode: Leave Ex mode, go back to
  246.             Normal mode.  Otherwise same as |:edit|, but set
  247.             'readonly' option for this buffer.  {not in Vi}
  248.  
  249.                             *CTRL-^*
  250. [count]CTRL-^        Edit [count]th alternate file (equivalent to ":e
  251.             #[count]").  Without count this gets you to the
  252.             previously edited file.  This is a quick way to toggle
  253.             between two (or more) files.
  254.             If the 'autowrite' or 'autowriteall' option is on and
  255.             the buffer was changed, write it.
  256.  
  257. [count]]f                        *]f* *[f*
  258. [count][f        Same as "gf".  Deprecated.
  259.  
  260.                             *gf* *E446* *E447*
  261. [count]gf        Edit the file whose name is under or after the cursor.
  262.             Mnemonic: "goto file".
  263.             Uses the 'isfname' option to find out which characters
  264.             are supposed to be in a file name.  Trailing
  265.             punctuation characters ".,:;!" are ignored.
  266.             Uses the 'path' option as a list of directory names
  267.             to look for the file.  Also looks for the file
  268.             relative to the current file.
  269.             Uses the 'suffixesadd' option to check for file names
  270.             with a suffix added.
  271.             If the file can't be found, 'includeexpr' is used to
  272.             modify the name and another attempt is done.
  273.             If a [count] is given, the count'th file that is found
  274.             in the 'path' is edited.
  275.             This command fails if Vim refuses to |abandon| the
  276.             current file.
  277.             If you do want to edit a new file, use: >
  278.                 :e <cfile>
  279. <            To make gf always work like that: >
  280.                 :map gf :e <cfile><CR>
  281. <            If the name is a hypertext link, that looks like
  282.             "type://machine/path", you need the |netrw| plugin.
  283.             For Unix the '~' character is expanded, like in
  284.             "~user/file".  Environment variables are expanded too
  285.             |expand-env|.
  286.             {not in Vi}
  287.             {not available when the |+file_in_path| feature was
  288.             disabled at compile time}
  289.  
  290.                             *v_gf*
  291. {Visual}[count]gf    Same as "gf", but the highlighted text is used as the
  292.             name of the file to edit.  'isfname' is ignored.
  293.             Leading blanks are skipped, otherwise all blanks and
  294.             special characters are included in the file name.
  295.             (For {Visual} see |Visual-mode|.)
  296.             {not in VI}
  297.  
  298. These commands are used to start editing a single file.  This means that the
  299. file is read into the buffer and the current file name is set.  The file that
  300. is opened depends on the current directory, see |:cd|.
  301.  
  302. See |read-messages| for an explanation of the message that is given after the
  303. file has been read.
  304.  
  305.                             *:filename*
  306. Note for systems other than Unix and MS-DOS: When using a command that
  307. accepts a single file name (like ":edit file") spaces in the file name are
  308. allowed, but trailing spaces are ignored.  This is useful on systems that
  309. allow file names with embedded spaces (like the Amiga).  Example: The command
  310. ":e   Long File Name " will edit the file "Long File Name".  When using a
  311. command that accepts more than one file name (like ":next file1 file2")
  312. embedded spaces must be escaped with a backslash.
  313.  
  314. You can use the ":e!" command if you messed up the buffer and want to start
  315. all over again.  The ":e" command is only useful if you have changed the
  316. current file name.
  317.  
  318.                     *backtick-expansion* *`-expansion*
  319. On Unix you can also use backticks in the file name, for example: >
  320.     :e `find . -name ver\\*.c -print`
  321. The backslashes before the star are required to prevent "ver*.c" to be
  322. expanded by the shell before executing the find program.
  323. This also works for most other systems, with the restriction that the
  324. backticks must be around the whole item.  It is not possible to have text
  325. directly before the first or just after the last backtick.
  326.  
  327. You can have the backicks expanded as a Vim expression, instead of
  328. an external command, by using the syntax `={expr}` e.g. >
  329.     :let foo='bar'
  330.     :e `=foo . ".c" `
  331. edits "bar.c".  Note that the expression cannot contain a backtick.
  332.  
  333.                             *++opt* *[++opt]*
  334. The [++opt] argument can be used to force the value of 'fileformat' or
  335. 'fileencoding' to a value for one command.  The form is: >
  336.     ++{optname}={value}
  337.  
  338. Where {optname} is one of:                *++ff* *++enc*
  339.     ff  or  fileformat        overrides 'fileformat'
  340.     enc  or  encoding        overrides 'fileencoding'
  341.  
  342. {value} cannot contain white space.  It can be any valid value for these
  343. options.  Examples: >
  344.     :e ++ff=unix
  345. This edits the same file again with 'fileformat' set to "unix". >
  346.  
  347.     :w ++enc=latin1 newfile
  348. This writes the current buffer to "newfile" in latin1 format.
  349.  
  350. Note that when reading, the 'fileformat' and 'fileencoding' options will be
  351. set to the used format.  When writing this doesn't happen, thus a next write
  352. will use the old value of the option.
  353.  
  354. There may be several ++opt arguments, separated by white space.  They must all
  355. appear before any |+cmd| argument.
  356.  
  357.                             *+cmd* *[+cmd]*
  358. The [+cmd] argument can be used to position the cursor in the newly opened
  359. file, or execute any other command:
  360.     +        Start at the last line.
  361.     +{num}        Start at line {num}.
  362.     +/{pat}        Start at first line containing {pat}.
  363.     +{command}    Execute {command} after opening the new file.
  364.             {command} is any Ex command.
  365. To include a white space in the {pat} or {command}, precede it with a
  366. backslash.  To end with a backslash, use a double backslash.
  367.     :edit  +/The\ book       file
  368.     :edit  +/dir\ dirname\\  file
  369.  
  370.                             *file-formats*
  371. The 'fileformat' option sets the <EOL> style for a file:
  372. 'fileformat'    characters       name                ~
  373.   "dos"        <CR><NL> or <NL>   DOS format        *DOS-format*
  374.   "unix"    <NL>           Unix format        *Unix-format*
  375.   "mac"        <CR>           Mac format        *Mac-format*
  376. Previously 'textmode' was used.  It is obsolete now.
  377.  
  378. When reading a file, the mentioned characters are interpreted as the <EOL>.
  379. In DOS format (default for MS-DOS, OS/2 and Win32), <CR><NL> and <NL> are both
  380. interpreted as the <EOL>.  Note that when writing the file in DOS format,
  381. <CR> characters will be added for each single <NL>.  Also see |file-read|.
  382.  
  383. When writing a file, the mentioned characters are used for <EOL>.  For DOS
  384. format <CR><NL> is used.  Also see |DOS-format-write|.
  385.  
  386. You can read a file in DOS format and write it in Unix format.  This will
  387. replace all <CR><NL> pairs by <NL> (assuming 'fileformats' includes "dos"): >
  388.     :e file
  389.     :set fileformat=unix
  390.     :w
  391. If you read a file in Unix format and write with DOS format, all <NL>
  392. characters will be replaced with <CR><NL> (assuming 'fileformats' includes
  393. "unix"): >
  394.     :e file
  395.     :set fileformat=dos
  396.     :w
  397.  
  398. If you start editing a new file and the 'fileformats' option is not empty
  399. (which is the default), Vim will try to detect whether the lines in the file
  400. are separated by the specified formats.  When set to "unix,dos", Vim will
  401. check for lines with a single <NL> (as used on Unix and Amiga) or by a <CR>
  402. <NL> pair (MS-DOS).  Only when ALL lines end in <CR><NL>, 'fileformat' is set
  403. to "dos", otherwise it is set to "unix".  When 'fileformats' includes "mac",
  404. and no <NL> characters are found in the file, 'fileformat' is set to "mac".
  405.  
  406. If the 'fileformat' option is set to "dos" on non-MS-DOS systems the message
  407. "[dos format]" is shown to remind you that something unusual is happening.  On
  408. MS-DOS systems you get the message "[unix format]" if 'fileformat' is set to
  409. "unix".  On all systems but the Macintosh you get the message "[mac format]"
  410. if 'fileformat' is set to "mac".
  411.  
  412. If the 'fileformats' option is empty and DOS format is used, but while reading
  413. a file some lines did not end in <CR><NL>, "[CR missing]" will be included in
  414. the file message.
  415. If the 'fileformats' option is empty and Mac format is used, but while reading
  416. a file a <NL> was found, "[NL missing]" will be included in the file message.
  417.  
  418. If the new file does not exist, the 'fileformat' of the current buffer is used
  419. when 'fileformats' is empty.  Otherwise the first format from 'fileformats' is
  420. used for the new file.
  421.  
  422. Before editing binary, executable or Vim script files you should set the
  423. 'binary' option.  A simple way to do this is by starting Vim with the "-b"
  424. option.  This will avoid the use of 'fileformat'.  Without this you risk that
  425. single <NL> characters are unexpectedly replaced with <CR><NL>.
  426.  
  427. You can encrypt files that are written by setting the 'key' option.  This
  428. provides some security against others reading your files. |encryption|
  429.  
  430.  
  431. File Searching                        *file-searching*
  432.  
  433. {not available when compiled without the |+path_extra| feature}
  434.  
  435. The file searching is currently used for the 'path', 'cdpath' and 'tags'
  436. options.  There are three different types of searching:
  437.  
  438. 1) Downward search:
  439.    Downward search uses the wildcards '*', '**' and possibly others
  440.    supported by your operating system. '*' and '**' are handled inside Vim, so
  441.    they work on all operating systems.
  442.  
  443.    The usage of '*' is quite simple: It matches 0 or more characters.
  444.  
  445.    '**' is more sophisticated:
  446.       - It ONLY matches directories.
  447.       - It matches up to 30  directories deep, so you can use it to search an
  448.     entire directory tree
  449.       - The maximum number of levels matched can be given by appending a number
  450.     to '**'.
  451.     Thus '/usr/**2' can match: >
  452.         /usr
  453.         /usr/include
  454.         /usr/include/sys
  455.         /usr/include/g++
  456.         /usr/lib
  457.         /usr/lib/X11
  458.         ....
  459. <    It does NOT match '/usr/include/g++/std' as this would be three
  460.     levels.
  461.     The allowed number range is 0 ('**0' is removed) to 255.
  462.     If the given number is smaller than 0 it defaults to 30, if it's
  463.     bigger than 255 it defaults to 255.
  464.       - '**' can only be at the end of the path or be followed by a path
  465.     separator or by a number and a path separator.
  466.  
  467.    You can combine '*' and '**' in any order: >
  468.     /usr/**/sys/*
  469.     /usr/*/sys/**
  470.     /usr/**2/sys/*
  471.  
  472. 2) Upward search:
  473.    Here you can give a directory and then search the directory tree upward for
  474.    a file. You could give stop-directories to limit the upward search. The
  475.    stop-directories are appended to the path (for the 'path' option) or to
  476.    the filename (for the 'tags' option) with a ';'. If you want several
  477.    stop-directories separate them with ';'. If you want no stop-directory
  478.    ("search upward till the root directory) just use ';'. >
  479.     /usr/include/sys;/usr
  480. <   will search in: >
  481.        /usr/include/sys
  482.        /usr/include
  483.        /usr
  484. <
  485.    If you use a relative path the upward search is started in Vim's current
  486.    directory or in the directory of the current file (if the relative path
  487.    starts with './' and 'd' is not included in 'cpoptions').
  488.  
  489.    If Vim's current path is /u/user_x/work/release and you do >
  490.     :set path=include;/u/user_x
  491. <  and then search for a file with |gf| the file is searched in: >
  492.     /u/user_x/work/release/include
  493.     /u/user_x/work/include
  494.     /u/user_x/include
  495.  
  496. 3) Combined up/downward search
  497.    If Vim's current path is /u/user_x/work/release and you do >
  498.     set path=**;/u/user_x
  499. <  and then search for a file with |gf| the file is searched in: >
  500.     /u/user_x/work/release/**
  501.     /u/user_x/work/**
  502.     /u/user_x/**
  503. <
  504.    BE CAREFUL! This might consume a lot of time, as the search of
  505.    '/u/user_x/**' includes '/u/user_x/work/**' and
  506.    '/u/user_x/work/release/**'.  So '/u/user_x/work/release/**' is searched
  507.    three and '/u/user_x/work/**' is searched two times.
  508.  
  509.    In the above example you might want to set path to: >
  510.     :set path=**,/u/user_x/**
  511. <   This searches: >
  512.     /u/user_x/work/release/**
  513.     /u/user_x/**
  514. <   This searches the same directories, but in a different order.
  515.  
  516. ==============================================================================
  517. 3. Dialogs                        *edit-dialogs*
  518.  
  519.                             *:confirm* *:conf*
  520. :conf[irm] {command}    Execute {command}, and use a dialog when an
  521.             operation has to be confirmed.  Can be used on the
  522.             ":q", ":qa" and ":w" commands (the latter to over-ride
  523.             a read-only setting).
  524.  
  525. Examples: >
  526.   :confirm w foo
  527. <    Will ask for confirmation when "foo" already exists. >
  528.   :confirm q
  529. <    Will ask for confirmation when there are changes. >
  530.   :confirm qa
  531. <    If any modified, unsaved buffers exist, you will be prompted to save
  532.     or abandon each one.  There are also choices to "save all" or "abandon
  533.     all".
  534.  
  535. If you want to always use ":confirm", set the 'confirm' option.
  536.  
  537.                             *:browse* *:bro* *E338*
  538. :bro[wse] {command}    Open a file selection dialog for an argument to
  539.             {command}.  At present this works for ":e", ":w",
  540.             ":r", ":sp", ":mkexrc", ":mkvimrc" and ":mksession".
  541.             {only in Win32, Motif and Athena GUI}
  542.             When ":browse" is not supported it's ignored,
  543.             {command} is executed without a dialog.
  544.  
  545. The syntax is best shown via some examples: >
  546.     :browse e $vim/foo
  547. <        Open the browser in the $vim/foo directory, and edit the
  548.         file chosen. >
  549.     :browse e
  550. <        Open the browser in the directory of the current buffer,
  551.         and edit the file chosen. >
  552.     :browse w
  553. <        Open the browser in the directory of the current buffer,
  554.         with the current buffer filename as default, and save the
  555.         buffer under the filename chosen. >
  556.     :browse w C:/bar
  557. <        Open the browser in the C:/bar directory, with the current
  558.         buffer filename as default, and save the buffer under the
  559.         filename chosen.
  560. Also see the |'browsedir'| option.
  561. For versions of Vim where browsing is not supported, the command is executed
  562. unmodified.
  563.  
  564.                             *browsefilter*
  565. For MS Windows, you can modify the filters that are used in the browse dialog.
  566. By setting the g:browsefilter or b:browsefilter variables, you can change the
  567. filters globally or locally to the buffer.  The variable is set to a string in
  568. the format "{filter label}\t{pattern};{pattern}\n" where {filter label} is the
  569. text that appears in the "Files of Type" comboBox, and {pattern} is the
  570. pattern which filters the filenames.  Several patterns can be given, separated
  571. by ';'.
  572.  
  573. For Motif the same format is used, but only the very first pattern is actually
  574. used (Motif only offers one pattern, but you can edit it).
  575.  
  576. For example, to have only Vim files in the dialog, you could use the following
  577. command: >
  578.  
  579.      let g:browsefilter="Vim Scripts\t*.vim\nVim Startup Files\t*vimrc\n"
  580.  
  581. You can override the filter setting on a per-buffer basis by setting the
  582. b:browsefilter variable.  You would most likely set b:browsefilter in a
  583. filetype plugin, so that the browse dialog would contain entries related to
  584. the type of file you are currently editing.  Disadvantage: This makes it
  585. difficult to start editing a file of a different type.  To overcome this, you
  586. may want to add "All Files\t*.*\n" as the final filter, so that the user can
  587. still access any desired file.
  588.  
  589. ==============================================================================
  590. 4. The current directory                *current-directory*
  591.  
  592. You may use the |:cd| and |:lcd| commands to change to another directory, so
  593. you will not have to type that directory name in front of the file names.  It
  594. also makes a difference for executing external commands, e.g. ":!ls".
  595.  
  596.                             *:cd*
  597. :cd            On non-Unix systems: Print the current directory
  598.             name.  On Unix systems: Change the current directory
  599.             to the home directory.  Use |:pwd| to print the
  600.             current directory on all systems.
  601.  
  602. :cd {path}        Change the current directory to {path}.
  603.             If {path} is relative, it is searched for in the
  604.             directories listed in |'cdpath'|.
  605.             Does not change the meaning of an already opened file,
  606.             because its full path name is remembered.  Files from
  607.             the |arglist| may change though!
  608.             On MS-DOS this also changes the active drive.
  609.  
  610.                             *:cd-* *E186*
  611. :cd -            Change to the previous current directory (before the
  612.             previous ":cd {path}" command). {not in Vi}
  613.  
  614.                             *:chd* *:chdir*
  615. :chd[ir] [path]        Same as |:cd|.
  616.  
  617.                             *:lc* *:lcd*
  618. :lc[d] {path}        Like |:cd|, but only set the current directory for the
  619.             current window.  The current directory for other
  620.             windows is not changed. {not in Vi}
  621.  
  622.                             *:lch* *:lchdir*
  623. :lch[dir]        Same as |:lcd|. {not in Vi}
  624.  
  625.                             *:pw* *:pwd* *E187*
  626. :pw[d]            Print the current directory name.  {Vi: no pwd}
  627.             Also see |getcwd()|.
  628.  
  629. So long as no |:lcd| command has been used, all windows share the same current
  630. directory.  Using a command to jump to another window doesn't change anything
  631. for the current directory.
  632. When a |:lcd| command has been used for a window, the specified directory
  633. becomes the current directory for that window.  Windows where the |:lcd|
  634. command has not been used stick to the global current directory.  When jumping
  635. to another window the current directory will become the last specified local
  636. current directory.  If none was specified, the global current directory is
  637. used.
  638. When a |:cd| command is used, the current window will lose his local current
  639. directory and will use the global current directory from now on.
  640.  
  641. After using |:cd| the full path name will be used for reading and writing
  642. files.  On some networked file systems this may cause problems.  The result of
  643. using the full path name is that the file names currently in use will remain
  644. referring to the same file.  Example: If you have a file a:test and a
  645. directory a:vim the commands ":e test" ":cd vim" ":w" will overwrite the file
  646. a:test and not write a:vim/test.  But if you do ":w test" the file a:vim/test
  647. will be written, because you gave a new file name and did not refer to a
  648. filename before the ":cd".
  649.  
  650. ==============================================================================
  651. 5. The argument list                *argument-list* *arglist*
  652.  
  653. If you give more than one file name when starting Vim, this list is remembered
  654. as the argument list.  You can jump to each file in this list.
  655.  
  656. Do not confuse this with the buffer list, which you can see with the
  657. |:buffers| command.  The argument list was already present in Vi, the buffer
  658. list is new in Vim.  A file name in the argument list will also be present in
  659. the buffer list (unless it was deleted with ":bdel").
  660.  
  661. This subject is introduced in section |07.2| of the user manual.
  662.  
  663. There is one global argument list, which is used for all windows by default.
  664. It is possible to create a new argument list local to a window, see
  665. |:arglocal|.
  666.  
  667. You can use the argument list with the following commands, and with the
  668. expression functions |argc()| and |argv()|.  These all work on the argument
  669. list of the current window.
  670.  
  671.                             *:ar* *:args*
  672. :ar[gs]            Print the argument list, with the current file in
  673.             square brackets.
  674.  
  675. :ar[gs] [++opt] [+cmd] {arglist}            *:args_f*
  676.             Define {arglist} as the new argument list and edit
  677.             the first one.  This fails when changes have been made
  678.             and Vim does not want to |abandon| the current buffer.
  679.             Also see |++opt| and |+cmd|.
  680.             {Vi: no ++opt}
  681.  
  682. :ar[gs]! [++opt] [+cmd] {arglist}            *:args_f!*
  683.             Define {arglist} as the new argument list and edit
  684.             the first one.  Discard any changes to the current
  685.             buffer.
  686.             Also see |++opt| and |+cmd|.
  687.             {Vi: no ++opt}
  688.  
  689. :[count]arge[dit][!] [++opt] [+cmd] {name}        *:arge* *:argedit*
  690.             Add {name} to the argument list and edit it.
  691.             When {name} already exists in the argument list, this
  692.             entry is edited.
  693.             This is like using |:argadd| and then |:edit|.
  694.             Note that only one file name is allowed, and spaces
  695.             inside the file name are allowed, like with |:edit|.
  696.             [count] is used like with |:argadd|.
  697.             [!] is required if the current file cannot be
  698.             |abandon|ed.
  699.             Also see |++opt| and |+cmd|.
  700.             {not in Vi}
  701.  
  702. :[count]arga[dd] {name} ..                *:arga* *:argadd*
  703.             Add the {name}s to the argument list.
  704.             If [count] is omitted, the {name}s are added just
  705.             after the current entry in the argument list.
  706.             Otherwise they are added after the [count]'th file.
  707.             If the argument list is "a b c", and "b" is the
  708.             current argument, then these commands result in:
  709.                 command        new argument list ~
  710.                 :argadd x    a b x c
  711.                 :0argadd x    x a b c
  712.                 :1argadd x    a x b c
  713.                 :99argadd x    a b c x
  714.             There is no check for duplicates, it is possible to
  715.             add a file to the argument list twice.
  716.             The currently edited file is not changed.
  717.             {not in Vi} {not available when compiled without the
  718.             |+listcmds| feature}
  719.             Note: you can also use this method: >
  720.                 :args ## x
  721. <            This will add the "x" item and sort the new list.
  722.  
  723. :argd[elete] {pattern} ..                *:argd* *:argdelete*
  724.             Delete files from the argument list that match the
  725.             {pattern}s.  {pattern} is used like a file pattern,
  726.             see |file-pattern|.  "%" can be used to delete the
  727.             current entry.
  728.             This command keeps the currently edited file, also
  729.             when it's deleted from the argument list.
  730.             {not in Vi} {not available when compiled without the
  731.             |+listcmds| feature}
  732.  
  733. :{range}argd[elete]    Delete the {range} files from the argument list.
  734.             When the last number in the range is too high, up to
  735.             the last argument is deleted.  Example: >
  736.                 :10,1000argdel
  737. <            Deletes arguments 10 and further, keeping 1-9.
  738.             {not in Vi} {not available when compiled without the
  739.             |+listcmds| feature}
  740.  
  741.                             *:argu* *:argument*
  742. :[count]argu[ment] [count] [++opt] [+cmd]
  743.             Edit file [count] in the argument list.  When [count]
  744.             is omitted the current entry is used.  This fails
  745.             when changes have been made and Vim does not want to
  746.             |abandon| the current buffer.
  747.             Also see |++opt| and |+cmd|.
  748.             {not in Vi} {not available when compiled without the
  749.             |+listcmds| feature}
  750.  
  751. :[count]argu[ment]! [count] [++opt] [+cmd]
  752.             Edit file [count] in the argument list, discard any
  753.             changes to the current buffer.  When [count] is
  754.             omitted the current entry is used.
  755.             Also see |++opt| and |+cmd|.
  756.             {not in Vi} {not available when compiled without the
  757.             |+listcmds| feature}
  758.  
  759. :[count]n[ext] [++opt] [+cmd]            *:n* *:ne* *:next* *E165* *E163*
  760.             Edit [count] next file.  This fails when changes have
  761.             been made and Vim does not want to |abandon| the
  762.             current buffer.  Also see |++opt| and |+cmd|.  {Vi: no
  763.             count or ++opt}.
  764.  
  765. :[count]n[ext]! [++opt] [+cmd]
  766.             Edit [count] next file, discard any changes to the
  767.             buffer.  Also see |++opt| and |+cmd|.  {Vi: no count
  768.             or ++opt}.
  769.  
  770. :n[ext] [++opt] [+cmd] {arglist}            *:next_f*
  771.             Same as |:args_f|.
  772.  
  773. :n[ext]! [++opt] [+cmd] {arglist}
  774.             Same as |:args_f!|.
  775.  
  776. :[count]N[ext] [count] [++opt] [+cmd]            *:Next* *:N* *E164*
  777.             Edit [count] previous file in argument list.  This
  778.             fails when changes have been made and Vim does not
  779.             want to |abandon| the current buffer.
  780.             Also see |++opt| and |+cmd|.  {Vi: no count or ++opt}.
  781.  
  782. :[count]N[ext]! [count] [++opt] [+cmd]
  783.             Edit [count] previous file in argument list.  Discard
  784.             any changes to the buffer.  Also see |++opt| and
  785.             |+cmd|.  {Vi: no count or ++opt}.
  786.  
  787. :[count]prev[ious] [count] [++opt] [+cmd]        *:prev* *:previous*
  788.             Same as :Next.  Also see |++opt| and |+cmd|.  {Vi:
  789.             only in some versions}
  790.  
  791.                             *:rew* *:rewind*
  792. :rew[ind] [++opt] [+cmd]
  793.             Start editing the first file in the argument list.
  794.             This fails when changes have been made and Vim does
  795.             not want to |abandon| the current buffer.
  796.             Also see |++opt| and |+cmd|. {Vi: no ++opt}
  797.  
  798. :rew[ind]! [++opt] [+cmd]
  799.             Start editing the first file in the argument list.
  800.             Discard any changes to the buffer.  Also see |++opt|
  801.             and |+cmd|. {Vi: no ++opt}
  802.  
  803.                             *:fir* *:first*
  804. :fir[st][!] [++opt] [+cmd]
  805.             Other name for ":rewind". {not in Vi}
  806.  
  807.                             *:la* *:last*
  808. :la[st] [++opt] [+cmd]
  809.             Start editing the last file in the argument list.
  810.             This fails when changes have been made and Vim does
  811.             not want to |abandon| the current buffer.
  812.             Also see |++opt| and |+cmd|.  {not in Vi}
  813.  
  814. :la[st]! [++opt] [+cmd]
  815.             Start editing the last file in the argument list.
  816.             Discard any changes to the buffer.  Also see |++opt|
  817.             and |+cmd|.  {not in Vi}
  818.  
  819.                             *:wn* *:wnext*
  820. :[count]wn[ext] [++opt] [+cmd]
  821.             Write current file and start editing the [count]
  822.             next file.  Also see |++opt| and |+cmd|.  {not in Vi}
  823.  
  824. :[count]wn[ext] [++opt] [+cmd] {file}
  825.             Write current file to {file} and start editing the
  826.             [count] next file, unless {file} already exists and
  827.             the 'writeany' option is off.  Also see |++opt| and
  828.             |+cmd|.  {not in Vi}
  829.  
  830. :[count]wn[ext]! [++opt] [+cmd] {file}
  831.             Write current file to {file} and start editing the
  832.             [count] next file.  Also see |++opt| and |+cmd|.  {not
  833.             in Vi}
  834.  
  835. :[count]wN[ext][!] [++opt] [+cmd] [file]        *:wN* *:wNext*
  836. :[count]wp[revous][!] [++opt] [+cmd] [file]        *:wp* *:wprevious*
  837.             Same as :wnext, but go to previous file instead of
  838.             next.  {not in Vi}
  839.  
  840. The [count] in the commands above defaults to one.  For some commands it is
  841. possible to use two counts.  The last one (rightmost one) is used.
  842.  
  843. If no [+cmd] argument is present, the cursor is positioned at the last known
  844. cursor position for the file.  If 'startofline' is set, the cursor will be
  845. positioned at the first non-blank in the line, otherwise the last know column
  846. is used.  If there is no last known cursor position the cursor will be in the
  847. first line (the last line in Ex mode).
  848.  
  849. The wildcards in the argument list are expanded and the file names are sorted.
  850. Thus you can use the command "vim *.c" to edit all the C files.  From within
  851. Vim the command ":n *.c" does the same.  On Unix you can also use backticks,
  852. for example: >
  853.     :n `find . -name \\*.c -print`
  854. The backslashes before the star are required to prevent "*.c" to be expanded
  855. by the shell before executing the find program.
  856.  
  857.                             *arglist-position*
  858. When there is an argument list you can see which file you are editing in the
  859. title of the window (if there is one and 'title' is on) and with the file
  860. message you get with the "CTRL-G" command.  You will see something like
  861.     (file 4 of 11)
  862. If 'shortmess' contains 'f' it will be
  863.     (4 of 11)
  864. If you are not really editing the file at the current position in the argument
  865. list it will be
  866.     (file (4) of 11)
  867. This means that you are position 4 in the argument list, but not editing the
  868. fourth file in the argument list.  This happens when you do ":e file".
  869.  
  870.  
  871. LOCAL ARGUMENT LIST
  872.  
  873. {not in Vi}
  874. {not available when compiled without the |+windows| or |+listcmds| feature}
  875.  
  876.                             *:arglocal*
  877. :argl[ocal]        Make a local copy of the global argument list.
  878.             Doesn't start editing another file.
  879.  
  880. :argl[ocal][!] [++opt] [+cmd] {arglist}
  881.             Define a new argument list, which is local to the
  882.             current window.  Works like |:args_f| otherwise.
  883.  
  884.                             *:argglobal*
  885. :argg[lobal]        Use the global argument list for the current window.
  886.             Doesn't start editing another file.
  887.  
  888. :argg[lobal][!] [++opt] [+cmd] {arglist}
  889.             Use the global argument list for the current window.
  890.             Define a new global argument list like |:args_f|.
  891.             All windows using the global argument list will see
  892.             this new list.
  893.  
  894. There can be several argument lists.  They can be shared between windows.
  895. When they are shared, changing the argument list in one window will also
  896. change it in the other window.
  897.  
  898. When a window is split the new window inherits the argument list from the
  899. current window.  The two windows then share this list, until one of them uses
  900. ":argslocal" or ":argsglobal" to use another argument list.
  901.  
  902.  
  903. USING THE ARGUMENT LIST
  904.  
  905.                         *:argdo*
  906. :argdo[!] {cmd}        Execute {cmd} for each file in the argument list.
  907.             It works like doing this: >
  908.                 :rewind
  909.                 :{cmd}
  910.                 :next
  911.                 :{cmd}
  912.                 etc.
  913. <            When the current file can't be |abandon|ed and the [!]
  914.             is not present, the command fails.
  915.             When an error is detected on one file, further files
  916.             in the argument list will not be visited.
  917.             The last file in the argument list (or where an error
  918.             occurred) becomes the current file.
  919.             {cmd} can contain '|' to concatenate several commands.
  920.             {cmd} must not change the argument list.
  921.             Note: While this command is executing, the Syntax
  922.             autocommand event is disabled by adding it to
  923.             'eventignore'.  This considerably speeds up editing
  924.             each file.
  925.             {not in Vi} {not available when compiled without the
  926.             |+listcmds| feature}
  927.             Also see |:windo| and |:bufdo|.
  928.  
  929. Example: >
  930.     :args *.c
  931.     :argdo set ff=unix | update
  932. This sets the 'fileformat' option to "unix" and writes the file if is now
  933. changed.  This is done for all *.c files.
  934.  
  935. Example: >
  936.     :args *.[ch]
  937.     :argdo %s/\<my_foo\>/My_Foo/ge | update
  938. This changes the word "my_foo" to "My_Foo" in all *.c and *.h files.  The "e"
  939. flag is used for the ":substitute" command to avoid an error for files where
  940. "my_foo" isn't used.  ":update" writes the file only if changes were made.
  941.  
  942. ==============================================================================
  943. 6. Writing                    *writing* *save-file*
  944.  
  945. Note: When the 'write' option is off, you are not able to write any file.
  946.  
  947.                             *:w* *:write*
  948. :[range]w[rite][!]    Write the specified lines to the current file.
  949.  
  950.                             *:w_f* *:write_f*
  951. :[range]w[rite]    {file}    Write the specified lines to {file}, unless it
  952.             already exists and the 'writeany' option is off.
  953.  
  954.                             *:w!*
  955. :[range]w[rite]! {file}    Write the specified lines to {file}.  Overwrite an
  956.             existing file.
  957.  
  958.                             *:w_a* *:write_a*
  959. :[range]w[rite][!] >>    Append the specified lines to the current file.
  960.  
  961. :[range]w[rite][!] >> {file}
  962.             Append the specified lines to {file}.  '!' forces the
  963.             write even if file does not exist.
  964.  
  965.                             *:w_c* *:write_c*
  966. :[range]w[rite] !{cmd}    Execute {cmd} with [range] lines as standard input
  967.             (note the space in front of the '!').  {cmd} is
  968.             executed like with ":!{cmd}", any '!' is replaced with
  969.             the previous command |:!|.
  970.  
  971. The default [range] for the ":w" command is the whole buffer (1,$).
  972. If a file name is given with ":w" it becomes the alternate file.  This can be
  973. used, for example, when the write fails and you want to try again later with
  974. ":w #".  This can be switched off by removing the 'A' flag from the
  975. 'cpoptions' option.
  976.  
  977.                             *:sav* *:saveas*
  978. :sav[eas][!] {file}    Save the current buffer under the name {file} and set
  979.             the filename of the current buffer to {file}.  The
  980.             previous name is used for the alternate file name.
  981.             The [!] is needed to overwrite an existing file.
  982.             {not in Vi}
  983.  
  984.                             *:up* *:update*
  985. :[range]up[date][!] [>>] [file]
  986.             Like ":write", but only write when the buffer has been
  987.             modified.  {not in Vi}
  988.  
  989.  
  990. Writing with multiple buffers                *buffer-write*
  991.  
  992.                             *:wa* *:wall*
  993. :wa[ll]            Write all changed buffers.  Buffers without a file
  994.             name or which are readonly are not written. {not in
  995.             Vi}
  996.  
  997. :wa[ll]!        Write all changed buffers, even the ones that are
  998.             readonly.  Buffers without a file name are not
  999.             written. {not in Vi}
  1000.  
  1001.  
  1002. Vim will warn you if you try to overwrite a file that has been changed
  1003. elsewhere.  See |timestamp|.
  1004.  
  1005.                             *backup* *E207*
  1006. If you write to an existing file (but do not append) while the 'backup',
  1007. 'writebackup' or 'patchmode' option is on, a backup of the original file is
  1008. made.  The file is either copied or renamed (see 'backupcopy').  After the
  1009. file has been successfully written and when the 'writebackup' option is on and
  1010. the 'backup' option is off, the backup file is deleted.  When the 'patchmode'
  1011. option is on the backup file may be renamed.
  1012.  
  1013.                             *backup-table*
  1014. 'backup' 'writebackup'    action    ~
  1015.    off         off    no backup made
  1016.    off         on        backup current file, deleted afterwards (default)
  1017.    on         off    delete old backup, backup current file
  1018.    on         on        delete old backup, backup current file
  1019.  
  1020. When the 'backupskip' pattern matches with the name of the file which is
  1021. written, no backup file is made.  The values of 'backup' and 'writebackup' are
  1022. ignored then.
  1023.  
  1024. When the 'backup' option is on, an old backup file (with the same name as the
  1025. new backup file) will be deleted.  If 'backup' is not set, but 'writebackup'
  1026. is set, an existing backup file will not be deleted.  The backup file that is
  1027. made while the file is being written will have a different name.
  1028.  
  1029. On some filesystems it's possible that in a crash you lose both the backup and
  1030. the newly written file (it might be there but contain bogus data).  In that
  1031. case try recovery, because the swap file is synced to disk and might still be
  1032. there. |:recover|
  1033.  
  1034. The directories given with the 'backupdir' option is used to put the backup
  1035. file in.  (default: same directory as the written file).
  1036.  
  1037. Whether the backup is a new file, which is a copy of the original file, or the
  1038. original file renamed depends on the 'backupcopy' option.  See there for an
  1039. explanation of when the copy is made and when the file is renamed.
  1040.  
  1041. If the creation of a backup file fails, the write is not done.  If you want
  1042. to write anyway add a '!' to the command.
  1043.  
  1044.                             *write-readonly*
  1045. When the 'cpoptions' option contains 'W', Vim will refuse to overwrite a
  1046. readonly file.  When 'W' is not present, ":w!" will overwrite a readonly file,
  1047. if the system allows it (the directory must be writable).
  1048.  
  1049.                             *write-fail*
  1050. If the writing of the new file fails, you have to be careful not to lose
  1051. your changes AND the original file.  If there is no backup file and writing
  1052. the new file failed, you have already lost the original file! DON'T EXIT VIM
  1053. UNTIL YOU WRITE OUT THE FILE! If a backup was made, it is put back in place
  1054. of the original file (if possible).  If you exit Vim, and lose the changes
  1055. you made, the original file will mostly still be there.  If putting back the
  1056. original file fails, there will be an error message telling you that you
  1057. lost the original file.
  1058.  
  1059.                         *DOS-format-write*
  1060. If the 'fileformat' is "dos", <CR> <NL> is used for <EOL>.  This is default
  1061. for MS-DOS, Win32 and OS/2.  On other systems the message "[dos format]" is
  1062. shown to remind you that an unusual <EOL> was used.
  1063.                         *Unix-format-write*
  1064. If the 'fileformat' is "unix", <NL> is used for <EOL>.  On MS-DOS, Win32 and
  1065. OS/2 the message "[unix format]" is shown.
  1066.                         *Mac-format-write*
  1067. If the 'fileformat' is "mac", <CR> is used for <EOL>.  On non-Mac systems the
  1068. message "[mac format]" is shown.
  1069.  
  1070. See also |file-formats| and the 'fileformat' and 'fileformats' options.
  1071.  
  1072.                         *write-device*
  1073. When the file name is actually a device name, Vim will not make a backup (that
  1074. would be impossible).  You need to use "!", since the device already exists.
  1075. Example for Unix: >
  1076.     :w! /dev/lpt0
  1077. and for MS-DOS or MS-Windows: >
  1078.     :w! lpt0
  1079. For Unix a device is detected when the name doesn't refer to a normal file or
  1080. a directory.  A fifo or named pipe also looks like a device to Vim.
  1081. For MS-DOS and MS-Windows the device is detected by its name:
  1082.     AUX
  1083.     CON
  1084.     CLOCK$
  1085.     NUL
  1086.     PRN
  1087.     COMn    n=1,2,3... etc
  1088.     LPTn    n=1,2,3... etc
  1089. The names can be in upper- or lowercase.
  1090.  
  1091. ==============================================================================
  1092. 7. Writing and quitting                    *write-quit*
  1093.  
  1094.                             *:q* *:quit*
  1095. :q[uit]            Quit the current window.  Quit Vim if this is the last
  1096.             window.  This fails when changes have been made and
  1097.             Vim refuses to |abandon| the current buffer, and when
  1098.             not editing the last file in the argument list.
  1099.  
  1100. :conf[irm] q[uit]    Quit, but give prompt when changes have been made, or
  1101.             not editing the last file in the argument list.  See
  1102.             |:confirm| and 'confirm'.  {not in Vi}
  1103.  
  1104. :q[uit]!        Quit without writing, also when visible buffers have
  1105.             changes.  Does not exit when there are changed hidden
  1106.             buffers.  Use ":qall!" to exit always.
  1107.  
  1108. :cq[uit]        Quit always, without writing, and return an error
  1109.             code.  See |:cq|.  Used for Manx's QuickFix mode (see
  1110.             |quickfix|).  {not in Vi}
  1111.  
  1112.                             *:wq*
  1113. :wq            Write the current file and quit (unless editing the
  1114.             last file in the argument list or the file is
  1115.             read-only).
  1116.  
  1117. :wq!            Write the current file and quit.
  1118.  
  1119. :wq {file}        Write to {file}.  Quit if not editing the last
  1120.             file in the argument list.
  1121.  
  1122. :wq! {file}        Write to {file} and quit.
  1123.  
  1124. :[range]wq[!] [file]    Same as above, but only write the lines in [range].
  1125.  
  1126.                             *:x* *:xit*
  1127. :[range]x[it][!] [file]
  1128.             Like ":wq", but write only when changes have been
  1129.             made.
  1130.             When 'hidden' is set and there are more windows, the
  1131.             current buffer becomes hidden, after writing the file.
  1132.  
  1133.                             *:exi* *:exit*
  1134. :[range]exi[t][!] [file]
  1135.             Same as :xit.
  1136.  
  1137.                             *ZZ*
  1138. ZZ            Write current file, if modified, and quit (same as
  1139.             ":x").  (Note: If there are several windows for the
  1140.             current file, the file is written if it was modified
  1141.             and the window is closed).
  1142.  
  1143.                             *ZQ*
  1144. ZQ            Quit without checking for changes (same as ":q!").
  1145.             {not in Vi}
  1146.  
  1147. MULTIPLE WINDOWS AND BUFFERS                *window-exit*
  1148.  
  1149.                             *:qa* *:qall*
  1150. :qa[ll]        Exit Vim, unless there are some buffers which have been
  1151.         changed.  (Use ":bmod" to go to the next modified buffer).
  1152.         When 'autowriteall' is set all changed buffers will be
  1153.         written, like |:wqall|. {not in Vi}
  1154.  
  1155. :conf[irm] qa[ll]
  1156.         Exit Vim.  Bring up a prompt when some buffers have been
  1157.         changed.  See |:confirm|. {not in Vi}
  1158.  
  1159. :qa[ll]!    Exit Vim.  Any changes to buffers are lost. {not in Vi}
  1160.  
  1161.                             *:quita* *:quitall*
  1162. :quita[ll][!]    Same as ":qall". {not in Vi}
  1163.  
  1164. :wqa[ll]                    *:wqa* *:wqall* *:xa* *:xall*
  1165. :xa[ll]        Write all changed buffers and exit Vim.  If there are buffers
  1166.         without a file name, which are readonly or which cannot be
  1167.         written for another reason, Vim is not quit. {not in Vi}
  1168.  
  1169. :conf[irm] wqa[ll]
  1170. :conf[irm] xa[ll]
  1171.         Write all changed buffers and exit Vim.  Bring up a prompt
  1172.         when some buffers are readonly or cannot be written for
  1173.         another reason.  See |:confirm|. {not in Vi}
  1174.  
  1175. :wqa[ll]!
  1176. :xa[ll]!    Write all changed buffers, even the ones that are readonly,
  1177.         and exit Vim.  If there are buffers without a file name or
  1178.         which cannot be written for another reason, Vim is not quit.
  1179.         {not in Vi}
  1180.  
  1181. ==============================================================================
  1182. 8. Editing binary files                    *edit-binary*
  1183.  
  1184. Although Vim was made to edit text files, it is possible to edit binary
  1185. files.  The |-b| Vim argument (b for binary) makes Vim do file I/O in binary
  1186. mode, and sets some options for editing binary files ('binary' on, 'textwidth'
  1187. to 0, 'modeline' off, 'expandtab' off).  Setting the 'binary' option has the
  1188. same effect.  Don't forget to do this before reading the file.
  1189.  
  1190. There are a few things to remember when editing binary files:
  1191. - When editing executable files the number of characters must not change.
  1192.   Use only the "R" or "r" command to change text.  Do not delete characters
  1193.   with "x" or by backspacing.
  1194. - Set the 'textwidth' option to 0.  Otherwise lines will unexpectedly be
  1195.   split in two.
  1196. - When there are not many <EOL>s, the lines will become very long.  If you
  1197.   want to edit a line that does not fit on the screen reset the 'wrap' option.
  1198.   Horizontal scrolling is used then.  If a line becomes too long (more than
  1199.   about 32767 characters on the Amiga, much more on 32-bit systems, see
  1200.   |limits|) you cannot edit that line.  The line will be split when reading
  1201.   the file.  It is also possible that you get an "out of memory" error when
  1202.   reading the file.
  1203. - Make sure the 'binary' option is set BEFORE loading the
  1204.   file.  Otherwise both <CR> <NL> and <NL> are considered to end a line
  1205.   and when the file is written the <NL> will be replaced with <CR> <NL>.
  1206. - <Nul> characters are shown on the screen as ^@.  You can enter them with
  1207.   "CTRL-V CTRL-@" or "CTRL-V 000" {Vi cannot handle <Nul> characters in the
  1208.   file}
  1209. - To insert a <NL> character in the file split up a line.  When writing the
  1210.   buffer to a file a <NL> will be written for the <EOL>.
  1211. - Vim normally appends an <EOL> at the end of the file if there is none.
  1212.   Setting the 'binary' option prevents this.  If you want to add the final
  1213.   <EOL>, set the 'endofline' option.  You can also read the value of this
  1214.   option to see if there was an <EOL> for the last line (you cannot see this
  1215.   in the text).
  1216.  
  1217. ==============================================================================
  1218. 9. Encryption                        *encryption*
  1219.  
  1220. Vim is able to write files encrypted, and read them back.  The encrypted text
  1221. cannot be read without the right key.
  1222.  
  1223. Note: The swapfile and text in memory is not encrypted.  A system
  1224. administrator will be able to see your text while you are editing it.
  1225.  
  1226. WARNING: If you make a typo when entering the key and then write the file and
  1227. exit, the text will be lost!
  1228.  
  1229. The normal way to work with encryption, is to use the ":X" command, which will
  1230. ask you to enter a key.  A following write command will use that key to
  1231. encrypt the file.  If you later edit the same file, Vim will ask you to enter
  1232. a key.  If you type the same key as that was used for writing, the text will
  1233. be readable again.  If you use a wrong key, it will be a mess.
  1234.  
  1235.                             *:X*
  1236. :X    Prompt for an encryption key.  The typing is done without showing the
  1237.     actual text, so that someone looking at the display won't see it.
  1238.     The typed key is stored in the 'key' option, which is used to encrypt
  1239.     the file when it is written.  See also |-x|.
  1240.  
  1241. The value of the 'key' options is used when text is written.  When the option
  1242. is not empty, the written file will be encrypted, using the value as the
  1243. encryption key.  A magic number is prepended, so that Vim can recognize that
  1244. the file is encrypted.
  1245.  
  1246. To disable the encryption, reset the 'key' option to an empty value: >
  1247.     :set key=
  1248.  
  1249. When reading a file that has been encrypted and this option is not empty, it
  1250. will be used for decryption.  If the value is empty, you will be prompted to
  1251. enter the key.  If you don't enter a key, the file is edited without being
  1252. decrypted.
  1253.  
  1254. If want to start reading a file that uses a different key, set the 'key'
  1255. option to an empty string, so that Vim will prompt for a new one.  Don't use
  1256. the ":set" command to enter the value, other people can read the command over
  1257. your shoulder.
  1258.  
  1259. Since the value of the 'key' option is supposed to be a secret, its value can
  1260. never be viewed.  You should not set this option in a vimrc file.
  1261.  
  1262. An encrypted file can be recognized by the "file" command, if you add this
  1263. line to "/etc/magic", "/usr/share/misc/magic" or wherever your system has the
  1264. "magic" file: >
  1265.      0    string    VimCrypt~    Vim encrypted file
  1266.  
  1267. Notes:
  1268. - Encryption is not possible when doing conversion with 'charconvert'.
  1269. - Text you copy or delete goes to the numbered registers.  The registers can
  1270.   be saved in the .viminfo file, where they could be read.  Change your
  1271.   'viminfo' option to be safe.
  1272. - Someone can type commands in Vim when you walk away for a moment, he should
  1273.   not be able to get the key.
  1274. - If you make a typing mistake when entering the key, you might not be able to
  1275.   get your text back!
  1276. - If you type the key with a ":set key=value" command, it can be kept in the
  1277.   history, showing the 'key' value in a viminfo file.
  1278. - There is never 100% safety.  The encryption in Vim has not been tested for
  1279.   robustness.
  1280. - The algorithm used is breakable.  A 4 character key in about one hour, a 6
  1281.   character key in one day (on a Pentium 133 PC).  This requires that you know
  1282.   some text that must appear in the file.  An expert can break it for any key.
  1283.   When the text has been decrypted, this also means that the key can be
  1284.   revealed, and other files encrypted with the same key can be decrypted.
  1285. - Pkzip uses the same encryption, and US Govt has no objection to its export.
  1286.   Pkzip's public file APPNOTE.TXT describes this algorithm in detail.
  1287. - Vim originates from the Netherlands.  That is where the sources come from.
  1288.   Thus the encryption code is not exported from the USA.
  1289.  
  1290. ==============================================================================
  1291. 10. Timestamps                    *timestamp* *timestamps*
  1292.  
  1293. Vim remembers the modification timestamp of a file when you begin editing it.
  1294. This is used to avoid that you have two different versions of the same file
  1295. (without you knowing this).
  1296.  
  1297. After a shell command is run (|:!cmd| |suspend| |:read!| |K|) timestamps are
  1298. compared for all buffers in a window.   Vim will run any associated
  1299. |FileChangedShell| autocommands or display a warning for any files that have
  1300. changed.  In the GUI this happens when Vim regains input focus.
  1301.  
  1302.                             *E321*
  1303. If you want to automatically reload a file when it has been changed outside of
  1304. Vim, set the 'autoread' option.  This doesn't work at the moment you write the
  1305. file though, only when the file wasn't changed inside of Vim.
  1306.  
  1307. Note that if a FileChangedShell autocommand is defined you will not get a
  1308. warning message or prompt.  The autocommand is expected to handle this.
  1309.  
  1310. There is no warning for a directory (e.g., in the |file-explorer|).  But you
  1311. do get warned if you started editing a new file and it was created as a
  1312. directory later.
  1313.  
  1314. When Vim notices the timestamp of a file has changed, and the file is being
  1315. edited in a buffer but has not changed, Vim checks if the contents of the file
  1316. is equal.  This is done by reading the file again (into a hidden buffer, which
  1317. is immediately deleted again) and comparing the text.  If the text is equal,
  1318. you will get no warning.
  1319.  
  1320. If you don't get warned often enough you can use the following command.
  1321.  
  1322.                             *:checkt* *:checktime*
  1323. :checkt[ime]        Check if any buffers were changed outside of Vim.
  1324.             This checks and warns you if you would end up with two
  1325.             versions of a file.
  1326.             If this is called from an autocommand, a ":global"
  1327.             command or is not typed the actual check is postponed
  1328.             until a moment the side effects (reloading the file)
  1329.             would be harmless.
  1330.             Each loaded buffer is checked for its associated file
  1331.             being changed.  If the file was changed Vim will take
  1332.             action.  If there are no changes in the buffer and
  1333.             'autoread' is set, the buffer is reloaded.  Otherwise,
  1334.             you are offered the choice of reloading the file.  If
  1335.             the file was deleted you get an error message.
  1336.             If the file previously didn't exist you get a warning
  1337.             if it exists now.
  1338.             Once a file has been checked the timestamp is reset,
  1339.             you will not be warned again.
  1340.  
  1341. :[N]checkt[ime] {filename}
  1342. :[N]checkt[ime] [N]
  1343.             Check the timestamp of a specific buffer.  The buffer
  1344.             may be specified by name, number or with a pattern.
  1345.  
  1346.  
  1347. Before writing a file the timestamp is checked.  If it has changed, Vim will
  1348. ask if you really want to overwrite the file:
  1349.  
  1350.     WARNING: The file has been changed since reading it!!!
  1351.     Do you really want to write to it (y/n)?
  1352.  
  1353. If you hit 'y' Vim will continue writing the file.  If you hit 'n' the write is
  1354. aborted.  If you used ":wq" or "ZZ" Vim will not exit, you will get another
  1355. chance to write the file.
  1356.  
  1357. The message would normally mean that somebody has written to the file after
  1358. the edit session started.  This could be another person, in which case you
  1359. probably want to check if your changes to the file and the changes from the
  1360. other person should be merged.  Write the file under another name and check for
  1361. differences (the "diff" program can be used for this).
  1362.  
  1363. It is also possible that you modified the file yourself, from another edit
  1364. session or with another command (e.g., a filter command).  Then you will know
  1365. which version of the file you want to keep.
  1366.  
  1367.  
  1368.  vim:tw=78:ts=8:ft=help:norl:
  1369.